package desktop;

import javax.swing.*;
import java.awt.*;

class Screen extends JFrame {
    private ScoreTable jPanel_score; //比赛分数表
    private JLabel title_match; //比赛名称
    private JLabel title_team; //组别名称
    private JLabel name_team1; //红队的队名
    private JLabel name_team2; //黄队的队名
    private JLabel image; //比赛图标

    Screen(String windowsName, int N){
        GridBagLayout layout = new GridBagLayout();
        this.setLayout(layout);
        GridBagConstraints s = new GridBagConstraints();
        s.fill = GridBagConstraints.BOTH;

        JPanel jPanel_topBar = new JPanel(); //标题栏
        //jPanel_topBar.setPreferredSize(new Dimension(300,150));
        jPanel_topBar.setLayout(new GridLayout(1,2,20,0));
        title_match = new JLabel("", JLabel.CENTER);
        title_match.setFont(new Font("宋体",Font.BOLD,40));
        title_match.setOpaque(true);
        title_match.setBackground(Color.WHITE);
        title_team = new JLabel("", JLabel.CENTER); //组别名称
        title_team.setPreferredSize(new Dimension(50,100));
        title_team.setFont(new Font("宋体",Font.BOLD,40));
        title_team.setOpaque(true);
        title_team.setForeground(Color.WHITE);
        title_team.setBackground(Color.BLUE);
        jPanel_topBar.add(title_match);
        jPanel_topBar.add(title_team);
        s.gridwidth = 0;//该方法是设置组件水平所占用的格子数，如果为0，就说明该组件是该行的最后一个
        s.gridheight = 1;//该方法是设置组件垂直所占用的格子数，如果为0，就说明该组件是该列的最后一个
        s.weightx = 0; //该方法设置组件水平的拉伸幅度，如果为0就说明不拉伸，不为0就随着窗口增大进行拉伸，0到1之间
        s.weighty = 0; //该方法设置组件垂直的拉伸幅度，如果为0就说明不拉伸，不为0就随着窗口增大进行拉伸，0到1之间
        s.insets = new Insets(10,0,10,0);
        layout.setConstraints(jPanel_topBar, s);//设置组件
        this.add(jPanel_topBar);

        JPanel jPanel2 = new JPanel(); //第二行
        jPanel2.setLayout(new GridLayout(1,2,0,0));
        image = new JLabel(); //比赛图标
        image.setIcon(new ImageIcon("src/main/resources/icon.jpg"));
        name_team1 = new JLabel("", JLabel.CENTER);
        name_team1.setFont(new Font("宋体",Font.BOLD,40));
        name_team1.setOpaque(true);
        name_team1.setBackground(Color.RED);
        name_team2 = new JLabel("", JLabel.CENTER);
        name_team2.setFont(new Font("宋体",Font.BOLD,40));
        name_team2.setOpaque(true);
        name_team2.setBackground(Color.YELLOW);
        jPanel2.add(image);
        jPanel2.add(name_team1);
        jPanel2.add(name_team2);
        layout.setConstraints(jPanel2, s);//设置组件
        this.add(jPanel2);

        jPanel_score = new ScoreTable(N); //比赛分数表，n场赛局
        s.gridheight = 3;//该方法是设置组件垂直所占用的格子数，如果为0，就说明该组件是该列的最后一个
        s.weightx = 1; //该方法设置组件水平的拉伸幅度，如果为0就说明不拉伸，不为0就随着窗口增大进行拉伸，0到1之间
        s.weighty = 1; //该方法设置组件垂直的拉伸幅度，如果为0就说明不拉伸，不为0就随着窗口增大进行拉伸，0到1之间
        layout.setConstraints(jPanel_score, s);//设置组件
        this.add(jPanel_score);

        this.setTitle(windowsName);
        this.setSize(1000,600);
        this.setVisible(false); //先不显示窗口
    }

    void showWindow(){
        if(this.isVisible())
            this.setVisible(false);
        else
            this.setVisible(true);
    }

    void setMatchName(String matchName) {
        title_match.setText(matchName);
    }

    void setGroupName(String groupName) {
        title_team.setText(groupName);
    }

    void setTeam1Name(String team1Name) {
        name_team1.setText(team1Name);
    }

    void setTeam2Name(String team2Name) {
        name_team2.setText(team2Name);
    }

    void setPicPath(String picPath) {
        image.setIcon(new ImageIcon(picPath));
    }

    void setPicIcon(Icon icon){
        image.setIcon(icon);
    }

    void setScore(boolean team, int match, int score){
        jPanel_score.updateScore(team,match,score);
    }

    void showTotalScore(){
        jPanel_score.showTotal();
    }

    void setFontSize_score(int fontSize_score){
        jPanel_score.setFontSize(fontSize_score);
    }

    int getFontSize_score(){
        return jPanel_score.getFontSize();
    }

    int getFontSize_title() {
        return title_match.getFont().getSize();
    }

    void setFontSize_title(int fontSize_title) {
        title_match.setFont(new Font("宋体",Font.BOLD,fontSize_title));
    }

    int getFontSize_team() {
        return name_team1.getFont().getSize();
    }

    void setFontSize_team(int fontSize_team) {
        name_team1.setFont(new Font("宋体",Font.BOLD,fontSize_team));
        name_team2.setFont(new Font("宋体",Font.BOLD,fontSize_team));
    }

    String getMatchTitle(){
        return title_match.getText();
    }

    Icon getImageIcon(){
        return image.getIcon();
    }

    String getGroupName(){
        return title_team.getText();
    }

    String getTeam1Name(){
        return name_team1.getText();
    }

    String getTeam2Name(){
        return name_team2.getText();
    }
}
